package com.base.api.bds;

import com.base.api.pms.PmsPublicSqlQuery;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.Map;

/**
 * @author wnhuang
 * @Package com.base.api.bds
 * @date 2020-12-12 16:49
 */
@Component
public class ChinaMapSqlQuery extends PmsPublicSqlQuery {
    @Override
    public String splicSql(String sql, Map<String, Object> param) {
        String param1 = "";
        //全国省级数据
        if (param != null && "1".equals(param.get("level"))) {
            param1 = " and t1.PROPERTY_DESCN1 ='1' ";
            return MessageFormat.format(sql, param1);
        }
        //具体某一个省的数据
        if (param != null && param.get("areaCode") != null && "2".equals(param.get("level"))) {
            param1 = " and t.BIRTH_ADDR_PROVINCE_CODE ='" + param.get("areaCode") + "' " + " and t1.PROPERTY_DESCN1 ='2'";
            return MessageFormat.format(sql, param1);
        }
        //具体某一个省的数据
        if (param != null && param.get("areaCode") != null && "3".equals(param.get("level"))) {
            param1 = " and t.BIRTH_ADDR_CITY_CODE ='" + param.get("areaCode") + "' " + " and t1.PROPERTY_DESCN1 ='3'";
            return MessageFormat.format(sql, param1);
        } else {
            throw new RuntimeException("参数拼接异常，" + param);
        }
    }
}
